package cn.stronglink.assetmanage.business.repair.order;


import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;
import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.business.check.assetlist.AssetListActivity;
import cn.stronglink.assetmanage.business.check.checkorder.CheckOrderAdapter;
import cn.stronglink.assetmanage.business.repair.assetlist.RepairDetailListActivity;
import cn.stronglink.assetmanage.entity.Check;
import cn.stronglink.assetmanage.entity.Repair;
import cn.stronglink.assetmanage.listener.onRecyclerListener;
import cn.stronglink.assetmanage.utils.Constants;
import cn.stronglink.assetmanage.utils.dao.CheckDataUtil;
import cn.stronglink.assetmanage.utils.dao.RepairDataUtil;

/**
 * 已入库表单列表
 * A simple {@link Fragment} subclass.
 */
public class RepairedFragment extends Fragment implements onRecyclerListener {
    private Unbinder mUnbinder;
    @BindView(R.id.rv_checked)
    RecyclerView rvChecked;
    private RepaierOrderAdapter mOrderAdapter;
    private List<Repair> repaieredList;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_checked, container, false);
        mUnbinder = ButterKnife.bind(this, view);
        return view;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        mOrderAdapter = new RepaierOrderAdapter(getActivity());
        mOrderAdapter.setListener(this);
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity(), LinearLayout.VERTICAL,
                false);
        rvChecked.setLayoutManager(layoutManager);
        rvChecked.setAdapter(mOrderAdapter);
        //显示本地数据
        showRepairData();
    }

    private void showRepairData() {
        repaieredList = RepairDataUtil.getDataByRepairedDistince();
        if (mOrderAdapter != null) {
            mOrderAdapter.notifyDataChanged(repaieredList);
        }
    }

    @Override
    public void onItemClicked(View v, int postion) {
        //跳转到UnCheckAsset界面
        Intent intent = new Intent(getActivity(), RepairDetailListActivity.class);
        intent.putExtra(Constants.SEARCH_REPAIR_NO, repaieredList.get(postion).getId_());
        startActivity(intent);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        mUnbinder.unbind();
    }
}
